package com.example.springrabbitmq.service;

import com.example.springrabbitmq.messaging.LoginMessage;
import com.example.springrabbitmq.messaging.RegistrationMessage;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author pan_jin
 * @Description: $
 * @Date: 2022/8/15 10:08
 * @Version: 1.0.0
 * @Slogan: 梦想还是要有的万一实现了呢
 */
@Component
public class MessageService {
    @Autowired
    RabbitTemplate rabbitTemplate;

    public void SendRegistrationMessage(RegistrationMessage msg) {
        rabbitTemplate.convertAndSend("registration", "", msg);
    }

    public void sendLoginMessage(LoginMessage msg) {
        String routingKey = msg.success ? "" : "login_failed";
        rabbitTemplate.convertAndSend("login", routingKey, msg);
    }
}
